Ad = require('../models/ad').Ad
resErr = require('./util').resErr
util = require("util")
config = require '../config'
http_request = require('../lib/utils').http_request
Dict = require('../models/dict').Dict

exports.analyse_uv = (req,res) ->
  url = config.services.bigdata.uv
  Dict.findOne {"key_code" : "common_config_edu_uv"},(err,data) ->
    return resErr res,err if err
    num = parseInt(data?.key_desc)
    if url 
      http_request "GET",url,null,(err,r) ->
        if r?.accumulate_uv
          num += parseInt(r?.accumulate_uv)
        return res.json {"uv" : num} 
    else
      return res.json {"uv" : num}